package cn.cloud9.opencloud.common.util;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

/**
 * @author OnCloud9
 * @description
 * @project Open-Cloud
 * @date 2022年04月16日 15:01
 */
public class EmptyUtil {
    private EmptyUtil() {}

    /**
     * 判断是否为空数组
     * @param array
     * @return
     */
    public static boolean isEmptyArray(Object[] array) {
        return array == null || array.length == 0 || Array.getLength(array) == 0;
    }
    public static boolean isEmptyArray(int[] array) {
        return array == null || array.length == 0;
    }
    public static boolean isEmptyArray(boolean[] array) {
        return array == null || array.length == 0;
    }
    public static boolean isEmptyArray(char[] array) {
        return array == null || array.length == 0;
    }
    public static boolean isEmptyArray(short[] array) {
        return array == null || array.length == 0;
    }
    public static boolean isEmptyArray(long[] array) {
        return array == null || array.length == 0;
    }
    public static boolean isEmptyArray(float[] array) {
        return array == null || array.length == 0;
    }
    public static boolean isEmptyArray(double[] array) {
        return array == null || array.length == 0;
    }

    /**
     * 判断字符串是否为空
     * @param string
     * @return
     */
    public static boolean isEmptyString(String string) {
        return string == null
                || string.length() == 0
                || string.trim().length() == 0
                || "\t".equals(string)
                || "\n".equals(string)
                || "undefined".equals(string)
                || "none".equals(string)
                || "unKnown".equals(string)
                || "null".equals(string);
    }

    /**
     * 判断集合是否空
     * @param collection
     * @return
     */
    public static boolean isEmptyCollection(Collection<?> collection) {
        return null == collection || collection.isEmpty();
    }

    /**
     * 判断Map是否空
     * @param map
     * @return
     */
    public static boolean isEmptyMap(Map<?, ?> map) {
        return null == map || map.isEmpty();
    }
}
